import { _decorator, Component, Label, Node } from 'cc';
import AbstractComponent from '../../../base/AbstractComponent';
import { BallInfoNode } from './BallInfoNode';
import { App } from '../../../App';
import { GameModel2 } from './GameModel2';
import { Ball } from '../Ball';
import GameUtils2 from './GameUtils2';
import { find } from 'cc';
import { tween } from 'cc';
import { Vec2 } from 'cc';
import { Vec3 } from 'cc';
import { UITransform } from 'cc';
import { view } from 'cc';
import UtilTool from '../../../tools/UtilTool';
const { ccclass, property } = _decorator;

@ccclass('GameTrainWin')
export class GameTrainWin extends AbstractComponent {

    // @property({type: [Material]})

    @property(Node)
    starList : Node = null

    @property(Node)
    bg : Node = null

    start() {
        App.Audio.playOneShot("game/win")
        this.showStars()

        this.node.getComponent(UITransform).setContentSize(view.getVisibleSize())
        UtilTool.nodeActive(this.bg, 5)
    }

    // 星星动画
    showStars() {

        let children : Node[] = this.starList.children

        for(let i=0; i<children.length; i++) {

            let item = children[i]
            item.active = false
            item.scale = new Vec3(5, 5, 1)

            tween(item).delay(i*0.45).call(()=>{
                item.active = true
            }).to(0.5, {scale:new Vec3(1,1,1)}, {easing:"sineInOut"}).start()
        }

    }

    onBtnAgain() {
        App.Audio.playOneShot("click");
        (App.Model.gameView as GameModel2).gameLogic.restart()
        this.node.destroy()
    }

    onBtnOk() {
        App.Audio.playOneShot("click")
        this.node.destroy();
        (App.Model.gameView as GameModel2).gameLogic.exitGame()
        this.backToHall()
    }

}
